package com.gxnzd.communityelderly.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.gxnzd.communityelderly.commom.R;
import com.gxnzd.communityelderly.entity.DrugLibrary;
import com.gxnzd.communityelderly.entity.Drugs;
import com.gxnzd.communityelderly.service.DrugLibraryService;
import com.gxnzd.communityelderly.service.DrugsService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * ClassName: DrugsController
 * Package: com.gxnzd.communityelderly.controller
 * Description:
 *
 * @Author 胡海峰
 * @Create 2024/10/21 11:00
 * @Version 1.0
 */
@RestController
@CrossOrigin
@RequestMapping("/drugs")
public class DrugsController {
    @Resource
    private DrugsService drugsService;
    @Resource
    private DrugLibraryService drugLibraryService;

    //列表
    @GetMapping("/list")
    public R<Page> list(Integer page, Integer pageSize, String drugsName, String manufacturer){
        return drugsService.selectPageList(page,pageSize,drugsName,manufacturer);
    }

    //根据药品名称查找
    @GetMapping("/queryKey")
    public R<List<Drugs>> queryKey(String drugsName){
        return drugsService.queryKey(drugsName);
    }

    //新增药品
    @PostMapping("/add")
    public R add(@RequestBody Drugs drugs){
        return drugsService.addDrugsInfo(drugs);
    }

    //修改
    @PutMapping("/update")
    public R update(@RequestBody Drugs drugs){
        return drugsService.updateDrugsInfo(drugs);
    }

    //查询药品详细信息
    @GetMapping("/{drugsId}")
    public R queryDetails(@PathVariable String drugsId){
        return drugsService.getDrugsDetails(drugsId);
    }

    //删除药品信息()
    @DeleteMapping("/{drugsId}")
    public R deleteDrugs(@PathVariable String drugsId){
        return drugsService.deleteDrugs(drugsId);
    }

    //药品库查询（要返回社区信息与药品信息）
    @GetMapping("/library/list")
    public R libraryList(Integer page, Integer pageSize,Long drugsId, Long communityId){
        return drugLibraryService.getLibraryList(page,pageSize,drugsId,communityId);
    }
    //对药品进行入库
    @PostMapping("/library/store")
    public R libraryStore(@RequestBody List<DrugLibrary> drugLibraryList){
        return drugLibraryService.bePutInStorage(drugLibraryList);
    }



    //查询药品库中的数据(通过关键字)
    @GetMapping("/library/queryKey")
    public R libraryQueryKey(String drugsName, Long communityId){
        return drugLibraryService.selectKeyword(drugsName,communityId);
    }
    //修改某个药品库中药品库存
    @PostMapping("/library/edit")
    public R editStock(@RequestBody DrugLibrary drugLibrary){
        return drugLibraryService.modifyInventory(drugLibrary);
    }
    //删除某个药品库
    @DeleteMapping("/library/delete")
    public R deleteStore(Integer drugsId,Integer communityId){
        return drugLibraryService.clearInventory(drugsId,communityId);
    }

    //获取药品库中某个药品的详细信息
    @GetMapping("/library/details")
    public R getDugrLibraryDetails(Long communityId,Long drugsId){
        return drugLibraryService.getDugrLibraryDInfo(communityId,drugsId);
    }
}
